#e
#Title[ΕuXJb^[htA -Lunatic-v]
#Text[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\lib_anime_Patchouli.txt"
	let imageBoss = GetCurrentScriptDirectory() ~ "img\dot_patchouli.png";

	let name	= "ΕuXJb^[htA -Lunatic-v";
	let imgRumia	= GetCurrentScriptDirectory~"img\ExRumia.png";
    	let csd        = GetCurrentScriptDirectory;
    	let shotImage   = csd ~ "data_usershot.txt";
	let RedFire	= 145;
	let BlueFire	= 150;

	let wIni = 120;
	
	///////////////////////////////////////////////////////////

	@Initialize{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
	LoadGraphic(imageBoss);
	InitializeAction();
	    
        SetMovePosition02(GetCenterX(), GetClipMinY+120, wIni);
        SetLife(5000);
        SetTimer(61);
	SetScore(500000);
        SetDamageRate(100, 20);
	SetInvincibility( 260 );
        LoadUserShotData(shotImage);

	TMain();
	TMain2();
	TSub();

	}
		
	@MainLoop{
	    SetCollisionA(GetX, GetY, 32);
	    SetCollisionB(GetX, GetY, 16);



	    yield;
	}
	
	@DrawLoop{
	    DrawBoss(imageBoss);
	    SetTexture(imageBoss);
	    DrawGraphic(GetX(), GetY());
	}
		
	@Finalize{
	    DeleteGraphic(imgRumia);
	}

	task TMain{

	    yield;
	    loop(wIni){ yield; }

	    loop{
	    fire;
	    loop(2){ yield;}
	    }
	}

	task TMain2{

	    yield;
	    loop(wIni){ yield; }

	    loop{
	    zenfire;
	    loop(40){ yield; }
	    }
	}

	task TSub{

	    yield;
	    loop(wIni){ yield; }

	    loop{
	    move;
	    loop(60){ yield; }
	    }
	}


	sub fire{
	CreateShotA(001,rand(GetX-100,GetX+100),rand(GetY-50,GetY+50),30);
	SetShotDataA(001,0,0,0,0,0,0,RedFire);
	SetShotDirectionType(PLAYER);
	SetShotDataA(001,100,4,rand(-5,5),0,0,4,RedFire);
	FireShot(001);
	}

	sub zenfire{
	    let Way	= 12;
	    let Base	= rand(0,360);
	    let dir	= 360/Way;
	    let angle	= Base;
	    ascent( let i in 0..Way ) {
		CreateShot02(GetX,GetY,8,Base+i*dir,-0.5,1,BlueFire,30);
	    }
	}

    // ړ
    sub move {
        let wMove = 40;

        moveToPlayer(rand(40, 80), rand(-40, 40), wMove,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
	SetAction(ACT_MOVE,wMove);
	wait(wMove);
	SetAction(ACT_STAND,wMove);
	wait(wMove);
    }

    // ȂׂvC[̕Ɉړ
    //   xMove  : x ̈ړʁi̐j
    //   yAdd   : y ̈ړ
    //   frame  : ړɗvt[
    //   left   : ȉA͈
    //   top    :
    //   right  :
    //   bottom :
    function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;

        if(GetPlayerX < GetX) {
            // vC[EɓG΁AG͍ɓ܂B
            x = GetX - xMove;

            // AAG̈̍[ɂ悤ȂAEɓ܂B
            if(x < left) {
                x = GetX + xMove;
            }
        } else {
            // Ȃ΁AG͉Eɓ܂B
            x = GetX + xMove;

            // AAG̈̉E[Eɂ悤ȂAɓ܂B
            if(right < x) {
                x = GetX - xMove;
            }
        }

        // ̈̊Oɍsꍇ́A[Ŏ~߂܂B
        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition02(x, y, frame);
    }

    // w t[҂
    function wait(w) {
        loop(w) { yield; }
    }
}